/**
 * @Author: LiMeng
 * @Date: 2017/3/22
 */
var edit_resource_func = function () {
    var $selected = $('#dg1').datagrid('getSelections');
    if ($selected.length !== 1) {
        layer.alert('请选择一个权限！');
        return false;
    }

    var index = layer.open({
        type: 2,
        title: '配置权限菜单',
        area: ['600px', '60%'],
        content: ROOT_PATH + '/permission/authorityResource/edit.shtml?id=' + $selected[0].id
    });
};
$(function () {
    //初始化加载datagrid
    $('#dg1').datagrid({
        method: 'post',
        url: ROOT_PATH + '/permission/authority/list.shtml',
        queryParams: {
            sort: 'addTime',
            order: 'desc'
        },
        toolbar: '#tb1',
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        sortOrder: true,
        striped: true,
        fit: true,
        columns: [[
            {field: 'id', checkbox: true},
            {field: 'code', title: '权限标识', width: 100, sortable: true},
            {field: 'name', title: '权限名称', width: 100, sortable: true},
            {
                field: 'groupId', title: '权限组名称', width: 100, sortable: true,
                formatter: function (value, row, index) {
                    if (row.authorityGroup) {
                        return row.authorityGroup.name;
                    } else {
                        return '';
                    }
                }
            }
        ]]
    });
    $('#authorityGroup').combobox({
        url: ROOT_PATH + '/permission/authorityGroup/getAuthorityGroupList.shtml',
        valueField: 'id',
        textField: 'name'
    });
    $('#btn_clear').on("click", function () {
        $('#tb1').form('reset');
    });
    $('#btn_search').on("click", function () {
        $('#dg1').datagrid('load', $('#tb1').find(':input').serializeJson());
    });
    $('#btn_authorityResource_edit').on('click', function () {
        edit_resource_func();
    });
});